<?php
namespace Cyfy\Modules\GoogleAnalytics;

/**
 * Simple module for inserting GA code into every page.
 *
 * @version 0.1
 * @author Dandelion
 */
class Module extends \Cyfy\Module
{
    /**
     * Administration
     * @return mixed
     */
    static function Administration($name="")
    {
        if($name == "settings")
        {
            $form = new Forms\Settings();
            $form -> setData(array("trackingCode" => self :: constant("trackingCode")));
            return $form -> show();
        }
        return array(
            "settings" => array("name" => self :: t(10), "description" => self :: t(20), "permission" => "administration"),
        );
    }
    /** 
     * Loading on start
     */    
    static function start()
    {
        $code = self :: constant("trackingCode");
        
        // code missing - exit
        if(!$code){
            return false;
        }
        
        // TEXT INCLUDED TO EVERY PAGE
        $js = <<<JAVASCRIPT

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', '{$code}']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

JAVASCRIPT;
        // CODE END
        \Cyfy\Cyfy ::  javaScript($js, "inline", "footer");		
    }
}